﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;
using System.ComponentModel;
using Water.Web.Controls.BaseInterface;

[assembly: WebResource("Water.Resources.Default.JS.TextBox.TextBox.js", "text/javascript")]
namespace Water.Web.Controls
{
    public abstract class BaseHiddenField : System.Web.UI.WebControls.HiddenField, ICallBackable, IUpdatedableControl, IPrompt
    {
        private string tokenCssClass;

        /// <summary>
        /// token css class (use photo)
        /// </summary>
        internal string TokenCssClass
        {
            get { return tokenCssClass; }
            set { tokenCssClass = value; }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            PageManager.Register(this);
            this.Page.ClientScript.RegisterClientScriptResource(typeof(BaseHiddenField), "Water.Resources.Default.JS.TextBox.TextBox.js");
            PageManager.RegisterPageStyleSheet(this, "TextBox_CSS", "CSS/TextBox.css");
        }

        protected virtual void RenderTokenAttribute(HtmlTextWriter writer)
        {
        }

        #region private字段

        private bool isCallBack = true;
        private string displayDuringCallBackTextControls;

        private bool isUpdateAfterCallBack = false;
        private UpdatedableControlRenderMode renderMode = UpdatedableControlRenderMode.Span;
        private string duringCallBackText = "";
        private string updateJS = "";
        private List<string> callBackControls = new List<string>();

        private int colSpan;
        private int rowSpan;
        private string prompt;


        #endregion

        #region override
        
        protected virtual void RenderDisplayContents(HtmlTextWriter writer)
        { 
        }
        /*
        protected override void RenderContents(HtmlTextWriter writer)
        {
            RenderDisplayContents(writer);
            base.RenderContents(writer);
        }

        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            if (this is IUpdatedableControl)
                Marker.WriteAJAXBegin(writer, this);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "field_package");
            writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_package");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            base.RenderBeginTag(writer);
        }
        public override void RenderEndTag(HtmlTextWriter writer)
        {
            base.RenderEndTag(writer);

            if (!string.IsNullOrEmpty(this.TokenCssClass))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Src, this.ResolveClientUrl(Path.ResourcePath) + "Images/TextBox/s.gif");
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "field_token " + this.TokenCssClass);
                writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_token");
                RenderTokenAttribute(writer);
                writer.RenderBeginTag(HtmlTextWriterTag.Img);
                writer.RenderEndTag();
                if (!string.IsNullOrEmpty(this.TokenCssClass))
                {
                    writer.Write("&nbsp;");
                    writer.Write("&nbsp;");
                    writer.Write("&nbsp;");
                    writer.Write("&nbsp;");
                }
            }
            writer.RenderEndTag();

            if (this is IUpdatedableControl)
                Marker.WriteAJAXEnd(writer, this);

        }
         */
        #endregion

        #region ICallBackable 成员

        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("IsCallBack"), DefaultValue(true)]
        public bool IsCallBack
        {
            get
            {
                return this.isCallBack;
            }
            set
            {
                this.isCallBack = value;
            }
        }
        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("CallBackTargets")]
        public string CallBackTargets
        {
            get
            {
                if (this.IsCallBack)
                {
                    return this.displayDuringCallBackTextControls;
                }
                return string.Empty;
            }
            set
            {
                this.displayDuringCallBackTextControls = value;
            }
        }

        #endregion

        #region IUpdatedableControl 成员
        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("AutoUpdatedAfterCallBack"), DefaultValue(false)]
        public bool AutoUpdatedAfterCallBack
        {
            get
            {
                return this.isUpdateAfterCallBack;
            }
            set
            {
                this.isUpdateAfterCallBack = value;
            }
        }
        [Browsable(false), DefaultValue(false)]
        public bool IsUpdatedAfterCallBack
        {
            get
            {
                return this.isUpdateAfterCallBack;
            }
            set
            {
                this.isUpdateAfterCallBack = value;
            }
        }

        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("DuringCallBackText")]
        public string DuringCallBackText
        {
            get
            {
                if (this.duringCallBackText != null)
                {
                    return this.duringCallBackText;
                }
                return string.Empty;
            }
            set
            {
                this.duringCallBackText = value;
            }
        }
        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("RenderMode"), DefaultValue(UpdatedableControlRenderMode.Span)]
        public UpdatedableControlRenderMode RenderMode
        {
            get
            {
                return this.renderMode;
            }
            set
            {
                this.renderMode = value;
            }
        }

        [Browsable(false), GlobalizeCategory("AJAX"), GlobalizeDescription("UpdateJS")]
        public virtual string UpdateJS
        {
            get
            {
                return this.updateJS;
            }
            set
            {
                this.updateJS = value;
            }
        }

        [Browsable(false)]
        public List<string> CallBackControls
        {
            get { return callBackControls; }
            set { callBackControls = value; }
        }
        #endregion

        #region IPrompt 成员

        [Browsable(true), GlobalizeCategory("PROMPT"), GlobalizeDescription("Prompt")]
        public string Prompt
        {
            get
            {
                return this.prompt;
            }
            set
            {
                this.prompt = value;
            }
        }
        [Browsable(true), GlobalizeCategory("PROMPT"), GlobalizeDescription("ColSpan")]
        public int ColSpan
        {
            get
            {
                return this.colSpan;
            }
            set
            {
                this.colSpan = value;
            }
        }
        [Browsable(true), GlobalizeCategory("PROMPT"), GlobalizeDescription("RowSpan")]
        public int RowSpan
        {
            get
            {
                return this.rowSpan;
            }
            set
            {
                this.rowSpan = value;
            }
        }

        #endregion
    }
}
